package proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 动态代理
 * */
public class DynamicProxy implements InvocationHandler {

    private Object targetObject;

    public DynamicProxy(Object targetObject) {
        this.targetObject = targetObject;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("In proxy, before speaking");
        Object invoke = method.invoke(targetObject, args);
        System.out.println("After speaking");
        return invoke;
    }
}
